<template>
    <div class="manage2">
        <el-button type="primary" class="manage2_button3" @click="addShow = true, addData = {}">新增</el-button>

    </div>
    <div class="list1" v-if="param.tablestatus == 1" v-loading="loading">
        <el-table ref="selectTable" :data="list1">
            <el-table-column prop="customerServiceId" min-width="120" label="客服ID"></el-table-column>
            <el-table-column prop="name" min-width="120" label="名称"></el-table-column>
            <el-table-column prop="mobile" min-width="120" label="手机号"></el-table-column>

            <el-table-column fixed="right" label="操作" min-width="200">
                <template #default="scope">
                    <div class="list1_operate1">
                        <el-button @click="addData = scope.row; addShow = true" text type="primary">编辑</el-button>
                        <el-divider class="list1_operate1_line1" direction="vertical" />
                        <el-button @click="tanchuang1(scope.row, 0)" text type="primary">删除</el-button>
                        <el-divider class="list1_operate1_line1" direction="vertical" />
                    </div>
                </template>
            </el-table-column>
        </el-table>


        <div class="list1_page1">
            <p class="list1_page1_title1">共 {{ total }} 条</p>
            <el-pagination v-model:currentPage="param.pageNumber" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :page-sizes="[10, 15, 20, 25]" :page-size="param.pageSize"
                layout=" sizes, prev , jumper , next" :total="total">
            </el-pagination>
        </div>
    </div>
    <el-dialog v-model="addShow" title="添加/编辑" width="760px" close-on-click-modal="false">
        <el-form :model="addData" ref="submitForm" label-width="auto" :rules="rules">
            <el-form-item label="名称：">
                <el-input type="name" class="w220" v-model="addData.name" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="电话：">
                <el-input type="mobile" class="w220" v-model="addData.mobile" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="客服id：">
                <el-input type="customerServiceId" class="w220" v-model="addData.customerServiceId" placeholder="请输入" />
            </el-form-item>

        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="addShow = false, addData = {}">取消</el-button>
                <el-button type="primary" @click="submit(addData)">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
<script>

export default {
    data() {
        return {
            dialogShow349: false,
            list1: [],
            addData: {},
            addShow: false,
            param: {
                pageNumber: 1,
                pageSize: 10,
                tablestatus: 1,
            },
            loading: false,
            total: 0,
            dialogShow391: false,
        }
    },

    created() {
        this.getList()
    },

    mounted() {
    },

    components: {

    },

    methods: {
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.param.pageSize = val;
            this.getList();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.param.pageNumber = val;
            this.getList();
        },
        getList(pageNumber) {
            this.loading = true;
            let res;
            if (pageNumber) {
                this.param.pageNumber = pageNumber;
            }
            this.$api.customerlist(this.param).then(res => {
                console.log('res====', res)
                if (res) {
                    let url = 'list' + this.param.tablestatus
                    this[url] = res.records
                    this.total = res.total;
                }
            })
            this.loading = false;
        },

        submit(addData) {
            console.log('addData', addData)
            let that = this
            if (addData.customerServiceId == null) {
                that.$api.insertcustomer(addData).then(res => {
                    console.log('添加返回', res)
                    that.getList();
                    that.addData = {}
                    that.addShow = false
                    that.$message.success(res.message);
                })

            }else{
                that.$api.updatecustomer(addData).then(res=>{
                console.log('添加返回',res)
                that.getList();
                that.addData = {}
                that.addShow = false
                that.$message.success(res.message);
            })


            }

        },


        tanchuang1(val, status) {
            let that = this;
            this.$msgbox.confirm(
                " ",
                "已删除",
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                }
            ).then(() => {
                this.$api.deletecustomer({ customerServiceId: val.customerServiceId }).then(res => {
                    console.log(res);
                    if (res) {
                        that.getList();
                        that.$message.success(res.message);
                    }
                })
            }).catch(() => { });
        },
    }

}


</script>
<style lang="scss" scoped>
.manage2 {
    padding: 10px 20px;
    background-color: #fff;
    text-align: left;

    .manage2_button1 {
        width: 115px;
        margin-top: 20px;
        margin-left: 16px;
    }

    .manage2_button2 {
        width: 115px;
        margin-top: 20px;
        margin-left: 10px;
    }

    .manage2_button3 {
        width: 115px;
        margin-top: 20px;
        margin-left: 10px;
    }

}

.list1 {
    background-color: #fff;

    .list1_head1 {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }

    .list1_operate1 {
        width: 100%;
        display: flex;
        justify-content: center;

        .list1_operate1_line1 {
            margin: auto 10px;
        }
    }

    .list1_page1 {
        height: 70px;
        padding: 20px;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .list1_page1_title1 {
            font-size: 10px;
            color: #A4A4A4;
        }
    }
}
</style>